package com.example.pei.ithinklearnt.view.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;

import com.example.pei.ithinklearnt.AppApplication;
import com.example.pei.ithinklearnt.R;
import com.example.pei.ithinklearnt.bean.FeedBack;
import com.example.pei.ithinklearnt.view.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

import static com.example.pei.ithinklearnt.utils.MyUtils.isAllSpace;

public class FeedBackActivity extends BaseActivity {

    @BindView(R.id.editText)
    EditText editText;


    @OnClick(R.id.btn_back)
    void back(){
        finish();
    }

    @OnClick(R.id.btn_submit)
    void sendSubmit(){

        String content=editText.getText().toString();
        if(isAllSpace(content)||content.length()<4){
            toast("这个字数也太敷衍了吧...");
            return;
        }

        FeedBack back = new FeedBack();
        back.setSender(AppApplication.getCurrentUser());
        back.setContent(content);
        back.save(new SaveListener<String>() {
            @Override
            public void done(String objectId,BmobException e) {
                if(e==null){
                    toast("感谢您的反馈٩( 'ω' )و 蟹蟹！");
                    finish();
                }else{
                    toast("反馈失败");
                }
            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feed_back);
    }
}
